
#include <QGLFormat>
#include <QGLWidget>
#include <QGraphicsProxyWidget>
#include <QRectF>
#include <QResizeEvent>
#include <QSize>

#include "core/engine.h"
#include "core/scene.h"
#include "core/view.h"

View::View(QWidget* pkParent)
    : QGraphicsView(pkParent)
{
    setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
    setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
}

View::~View()
{
}

QSize View::sizeHint() const
{
    return QSize(800, 600);
}

void View::resizeEvent(QResizeEvent* pkEvent)
{
    Engine::instance().scene().setSceneRect(0, 0, pkEvent->size().width(), pkEvent->size().height());
    static_cast< QGraphicsProxyWidget* >(Engine::instance().scene().items().at(0))->setGeometry(QRectF(0, 0, pkEvent->size().width(), pkEvent->size().height()));

    // Forward event.
    QGraphicsView::resizeEvent(pkEvent);
}
